<div class="layout-content">
  <div class="layout-content-main">
    <div class="container">
      <div class="row">
        <% posts.forEach(function(post) { %>
        <article class="card-list col-12 col-sm-12 col-md-6 col-lg-4 col-xl-4">
          <div class="layout-card">
            <div class="layout-card-body">
              <a class="layout-card-thumb" href="<%= post.link %>">
                <div class="layout-thumb" style="background-image: url('<%= post.feature %>')">
                </div>
                <div class="layout-thumb-mask"></div>
              </a>

              <div class="layout-card-content">
                <h2 class="layout-title"><a href="<%= post.link %>"><%= post.title %></a></h2>
                <div class="layout-meta">
                  <div class="layout-meta-list">
                    <span><%= post.dateFormat %></span>
                  </div>
                  <div class="layout-meta-list col-right">
                    <a href="<%= post.link %>">阅读</a>
                  </div>
                </div>
              </div>

            </div>
          </div>
        </article>
        <% }); %>
      </div>
      <% if (pagination.next) { %>
      <div class="layout-paginator">
        <div class="paginator">
          <button href="<%= pagination.next %>" class="btn btn-paginator width-100">加载更多</button>
        </div>
      </div>
      <% } %>
    </div>
  </div>
</div>


<script type="text/javascript">
  //点击加载更多
  jQuery(document).ready(function ($) {
    //点击下一页的链接(即那个a标签)
    $(' .btn-paginator').click(function () {
      $this = $(this);
      $this.addClass('loading').text('正在努力加载'); //给a标签加载一个loading的class属性，用来添加加载效果
      var href = $this.attr('href'); //获取下一页的链接地址
      if (href != undefined) { //如果地址存在
        $.ajax({ //发起ajax请求
          url: href,
          //请求的地址就是下一页的链接
          type: 'get',
          //请求类型是get
          error: function (request) {
            //如果发生错误怎么处理
          },
          success: function (data) { //请求成功
            $this.removeClass('loading').text('加载更多'); //移除loading属性
            var $res = $(data).find('.card-list '); //从数据中挑出文章数据，请根据实际情况更改
            $('.row').append($res.fadeIn(
              500)); //将数据加载加进posts-loop的标签中。
            var newhref = $(data).find('.btn-paginator').attr('href'); //找出新的下一页链接
            if (newhref != undefined) {
              $('.btn-paginator').attr('href', newhref);
            } else {
              $('.btn-paginator').remove(); //如果没有下一页了，隐藏
            }
          }
        });
      }
      return false;
    });
  });
</script>